package com.rjpacket.supernews.app.tasks;

import android.os.AsyncTask;
import com.rjpacket.supernews.app.utils.HttpTool;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by aaa on 15-3-13.
 */
public class SplashPhotoJsonTask extends AsyncTask<String, Integer, JSONObject> {
    private TaskCallOnBack back;

    public SplashPhotoJsonTask(TaskCallOnBack back) {
        this.back = back;
    }

    @Override
    protected JSONObject doInBackground(String... params) {
        JSONObject ret = null;

        String url = params[0];

        if (url != null) {
            byte[] bytes = HttpTool.get(url);

            if (bytes != null) {
                String str = new String(bytes);

                try {
                    ret = new JSONObject(str);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }

        return ret;
    }

    @Override
    protected void onPostExecute(JSONObject jsonObject) {

        back.callOnBack(jsonObject);

    }
}
